home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2003 June / macformat-130.iso / mac / Reviewed⁄Demos / Spearhead Demo / demota / pak1.pk3 / global / stationaryweapons.scr < prev    next >
Encoding:
Text File  |  2002-10-29  |  6.4 KB  |  254 lines

  1. //
  2. // Utility script to add damaged model to destroyed stationary tiki model
  3. //
  4. // there are two types
  5. // type 2: Stationary
  6. // type 1: Player mounted
  7.  
  8. /*
  9.  
  10. When you place a player useable weapon lets say for example an AA gun like the one in T1L1 you may want to swap it out when it gets destroyed to do this there is a new script in the global folder to use it all you need to do is simply follow these simple steps.
  11.  
  12. Steps in Radiant:
  13.  
  14. 1. Make a turret weapon in Radiant
  15. 2. Give the weapon a $targetname
  16. 3. Give it a health
  17. 4. if you want it to block when it gets destroyedÖ have it target the collision geometry
  18.  
  19. Steps in your script:
  20.  
  21. 1.    In your main script you need to add right after level waittill spawn
  22. The $targetname of the weapon followed by the following thread
  23.  
  24. Ei. Lets say we have called a player mountable turret $targetname gun1
  25.  
  26. The script would read
  27.  
  28. $gun1 thread global/stationaryweapons.scr::MountedStationaryWeapon statweapons/P_aagun_d.tik
  29.  
  30. so just replace the stuff in the [ change this ] 
  31.  
  32. [ $targetname ] thread global/stationaryweapons.scr::MountedStationaryWeapon [ NAME OF THE DESTROYED TIKI ]
  33. */
  34.  
  35. // 
  36. // Player Mounted
  37. //
  38. //
  39. // use with "turretweapon_player_aagun-winter" type weapons
  40. //
  41. // to use this call this thread
  42. // 
  43. // [self] thread global/stationaryweapons.scr::MountedStationaryWeapon statweapons/P_aagun_d.tik 
  44. //
  45. // local.destroyedmodel = model to display when you blow it up
  46. //
  47. // [self] thread global/stationaryweapons.scr::MountedStationaryWeaponWithCollision statweapons/P_aagun_d.tik [ $collision ]
  48. //
  49.  
  50.  
  51. MountedStationaryWeaponWithCollision local.destroyedmodel local.collision:
  52.  
  53.     //
  54.     // give everything a chance to settle before grabbing origin and angles
  55.     //
  56.     wait 0.25
  57.  
  58.     local.origin = self.origin
  59.  
  60.     self waittill death
  61.  
  62.     exec global/earthquake.scr .2 4 0 0
  63.  
  64.     radiusdamage self.origin 200 200
  65.                  
  66.     self thread spawn_fx models/fx/fx_truck_explosion.tik
  67.  
  68.     local.damaged = spawn script_model model local.destroyedmodel 
  69.  
  70.     // make the new thing immobile
  71.     local.damaged mass 100000
  72.  
  73.     local.damaged.origin = local.origin
  74.  
  75.     local.gun = self QueryTurretSlotEntity 0
  76.  
  77.     //
  78.     // get correct orientation if available
  79.     //
  80.     if ( local.gun )
  81.     {
  82.         local.damaged.angles = local.gun.angles
  83.     }
  84.     else
  85.     {
  86.         local.damaged.angles = self.angles
  87.     }
  88.     local.damaged notsolid
  89.  
  90.     if (local.collision)
  91.     {
  92.         local.col = spawn script_object model local.collision.brushmodel
  93.         local.col.origin = local.damaged.origin
  94.         local.col.angles = local.damaged.angles
  95.         local.col safesolid
  96.     }
  97. end
  98.  
  99.  
  100. MountedStationaryWeapon local.destroyedmodel:
  101.  
  102.     local.origin = self.origin
  103.     local.angles = self.angles
  104.     local.brushmodel = 0
  105.     
  106.     self waittill death
  107.  
  108. //dprintln "MountedStationaryWeapon triggered"
  109.  
  110.     local.damaged = spawn script_model model local.destroyedmodel 
  111.  
  112.     local.damaged.origin = local.origin
  113.     local.damaged.angles = local.angles
  114.     local.damaged notsolid
  115.  
  116. //dprintln "MountedStationaryWeapon damaged"
  117.  
  118. end
  119.  
  120.  
  121. SpawnCollision local.collision:
  122.     local.col = spawn script_object model local.collision.brushmodel
  123.     local.col.origin = self.origin
  124.     local.col.angles = self.angles
  125.     local.col safesolid
  126. end
  127.  
  128.  
  129. /*
  130. The script also supports script_model_realdamage entities this would be used when you don't want the player to use these weapons
  131.  
  132.  
  133. Steps in Radiant:
  134.  
  135. 1.    create a script_model_realdamage entity
  136. 2.    give this entity a $targetname
  137. 3.    give it a health
  138. 4.    make a collision mask and have the entity target it
  139.  
  140. Steps in your script:
  141.  
  142. 1.    right after your level wait till spawn
  143. 2.    call the thread that will swap the weapon with a destroyed model and give it its collision model
  144.  
  145. ei. $enemy_gun1 thread global/stationaryweapons.scr::StationaryWeapon statweapons/nebelwerfer_w_d.tik 128 200 300
  146.  
  147. this thread will do the following it will upon death of $enemy_gun1 which is a nebelwerfer swap it out with a destroyed version of this weapon and generate upon death a radius damage 128 units above the origin of this entity with a damage of 200 and a radius of 300
  148.  
  149. [ $targetname ]  thread global/stationaryweapons.scr::StationaryWeapon [ name of destroyed tiki ] [ heightoffset ] [ damage ] [ radius ]
  150.  
  151.  
  152. */
  153. // 
  154. // Stationary 
  155. // 
  156. // use with "script_model_realdamage" entities
  157. // 
  158. // [self] thread global/stationaryweapons.scr::StationaryWeapon statweapons/nebelwerfer_w_d.tik 128 200 300
  159. //
  160. // local.destroyedmodel = model to display when you blow it up
  161. // local.heightdamageoffset = how high from the origin to do a radius damage 
  162. // local.damage = how much damage to inflict upon death
  163. // local.radius = radius to inflict damage
  164.  
  165. StationaryWeapon local.destroyedmodel local.heightdamageoffset local.damage local.radius:
  166.  
  167. // dprintln "StationaryWeapon called"
  168.  
  169.     while (isalive self)
  170.         waitframe
  171.  
  172. // dprintln "StationaryWeapon triggered"
  173.  
  174.     if !(local.damage)
  175.         local.damage = 200
  176.  
  177.     if !(local.radius)
  178.         local.radius = 200
  179.     
  180.     self.destroyedmodel = local.destroyedmodel
  181.  
  182.     self show
  183.     self playsound explode_tank
  184.     self stop
  185.  
  186.     if (self.mg42)
  187.     {
  188.         self DetachTurretSlot 0
  189.         self.mg42 stopfiring
  190.         self.mg42 remove
  191.     }
  192.     if ($(self.gunner))
  193.     {
  194.         self DetachPassengerSlot 1 self.gunner.origin
  195.         self.gunner remove
  196.     }
  197.     
  198.     exec global/earthquake.scr .2 4 0 0
  199.  
  200.     if (local.heightdamageoffset)
  201.     {
  202.         radiusdamage (self.origin + (0 0 local.heightdamageoffset)) local.damage local.radius
  203.     }
  204.     else
  205.         radiusdamage (self.origin + (0 0 128)) local.damage local.radius
  206.                  
  207.     // self thread spawn_fx models/fx/fx_tank_explosion.tik
  208.  
  209.     local.name = self
  210.     local.angles = self.angles
  211.     local.origin = self.origin
  212.     local.brushmodel = self.collisionent.brushmodel
  213.     
  214.     self hide
  215.     self notsolid
  216.  
  217.     if (self.target)
  218.     {
  219.         self.collisionent = self.target
  220.         local.brushmodel = self.collisionent.brushmodel
  221.     }
  222.  
  223.     if (local.brushmodel)
  224.     {
  225.         local.collision = spawn script_object model local.brushmodel
  226.         local.collision.origin = local.origin
  227.         local.collision.angles = local.angles
  228.         local.collision safesolid
  229.     }
  230.     
  231.     local.damaged = spawn script_model model self.destroyedmodel
  232.  
  233.     local.damaged.origin = local.origin
  234.     local.damaged.angles = local.angles
  235.     local.damaged notsolid
  236.  
  237. // dprintln "StationaryWeapon destroyed"
  238.     
  239.     wait .5
  240.     if (self)
  241.         self remove
  242.  
  243. end
  244.  
  245. spawn_fx local.fx:
  246.     local.temp = spawn script_model model local.fx
  247.     local.temp notsolid
  248.     local.temp.origin = self.origin
  249.     local.temp anim start
  250.     local.temp notsolid
  251.     wait 5
  252.     local.temp remove
  253. end
  254.